package com.snailhd.scheduled;

import com.snailhd.constant.SinaEnum;
import com.snailhd.crawler.CrawlStockListExector;
import com.snailhd.entity.Stock;
import com.snailhd.mapper.StockMapper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时维护stock
 * @author hd
 * @date 2019-12-01 13:05
 */

@Slf4j
@Component
@JobHandler("stockListMaintainScheduled")
public class StockListMaintainScheduled extends IJobHandler {

    @Resource
    CrawlStockListExector crawler;

    @Resource
    StockMapper stockMapper;

    @Override
    public ReturnT<String> execute(String args) throws Exception {
        log.info(StringUtils.center("stockListMaintainSheduled start !!!",80,"*"));
        List<Stock> stocks = crawler.exec(SinaEnum.sh_a,SinaEnum.sz_a);
        stockMapper.insertMulti(stocks);
        log.info(StringUtils.center("stockListMaintainSheduled end !!!",80,"*"));
        return SUCCESS;
    }
}
